// pages/staff/my.js
const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        tel:'',
        userInfo:'',
        tuifalse:false,
        firstfalse: false,
        secfalse: false,
        threefalse: true,
        identity:1,  //1学员 2课程顾问
        navarrobj: {},
        everyitem: '',
        tanfalse: false,
    },

  
  
  // 点击退出登录
  tuiclick:function(){
    this.setData({
      tuifalse:true
    })
  },
// 点击退出登录  取消
  noclick:function(){
    this.setData({
      tuifalse: false
    })
  },

  onHide:function(){
    this.setData({
      tuifalse: false
    })
  },
  
  // 点击退出登录  确定
  yesclick: function () {
    this.setData({
      tuifalse: false
    })
    wx.removeStorage({
      key: 'tel',
      success: function () {
        wx.showToast({
          title: '退出登录成功',
          icon:'none',
          duration:1500
        })

        setTimeout(function(){
          wx.redirectTo({
              url: '/pages/loginfirst',
          })        
        },300)
      },
      fail: function () {
        wx.showModal({
          title: CONFIG.MODEL_TITLE,
          showCancel: false,
          content: CONFIG.REQUEST_FAIL,
          confirmText: '点击重试',
          success: function (res) {
            wx.navigateBack();
          }
        })
      }
    })
  },


    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        // console.log(app.globalData.userInfo);
        var that = this;
        that.setData({
            userInfo:app.globalData.userInfo
        })
        var identity = app.globalData.identity;
        that.setData({
            identity: identity
        })
        wx.getStorage({
            key: 'tel',
            success: function (res) {
                // console.log(res.data);
                var tel = res.data;
                that.setData({
                    tel: tel.replace(tel.substr(3, 4), "****")
                })
            }
        });
        var navarr = JSON.parse(wx.getStorageSync('navarr'));
        var item = '';
        for (var i = 0; i < navarr.length; i++) {
            if (navarr[i].name == 'my') {
                item = navarr[i];
            }
        }
        var obj = {
            navarr: navarr,
            typestatus: 'my',
        }
        that.setData({
            navarrobj: obj,
            everyitem: item,
            tanfalse: true,
        })

    },

    onShow: function (options) {
        // console.log(app.globalData.userInfo);
        var that = this;
        that.setData({
            userInfo: app.globalData.userInfo
        })

        wx.getStorage({
            key: 'tel',
            success: function (res) {
                // console.log(res.data);
                var tel = res.data;
                that.setData({
                    tel: tel.replace(tel.substr(3, 4), "****")
                })
            },
            fail:function(res){
                // console.log(898)
                that.setData({
                    tel:'',
                })
                wx.redirectTo({
                    url: '/pages/loginfirst',
                })
            }
        });
    },

  // 点击登录
  loginclick:function(){
    wx.navigateTo({
      url: '../login',
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: CONFIG.SHARETITLE,
      path: CONFIG.PATHLOGIN
    }
  }
})